unit untConsultaDAP;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, untConsultaPadrao, ACBrBase, ACBrEnterTab, dxmdaset, dxBarDBNav,
  dxBar, cxClasses, DB, IBCustomDataSet, ActnList, cxPropertiesStore,
  cxContainer, cxEdit, cxStyles, cxGridTableView, cxLookAndFeels,
  cxGridCustomPopupMenu, cxGridPopupMenu, ImgList, cxGraphics, ExtCtrls,
  cxPC, cxControls, cxCustomData, cxFilter, cxData, cxDataStorage,
  cxDBData, cxCurrencyEdit, cxGridLevel, cxGridCustomTableView,
  cxGridDBTableView, cxGridCustomView, cxGrid, cxDropDownEdit, cxCalc,
  cxDBEdit, cxSpinEdit, cxLabel, cxTextEdit, cxMaskEdit, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, cxGridBandedTableView,
  cxGridDBBandedTableView, IBQuery,DateUtils, cxIntlBase, cxintl,
  ppParameter, ppBands, ppCtrls, jpeg, ppPrnabl, ppClass, ppCache, ppProd,
  ppReport, ppEndUsr, ppDB, ppComm, ppRelatv, ppDBPipe, ppStrtch, ppSubRpt,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, dxSkinsdxBarPainter, ppRichTx;

type
  TfrmConsultaDAP = class(TfrmConsultaPadrao)
    Panel3: TPanel;
    cbPropriedade: TcxDBLookupComboBox;
    cxLabel6: TcxLabel;
    cxLabel1: TcxLabel;
    cxDBSpinEdit1: TcxDBSpinEdit;
    Panel4: TPanel;
    Grid: TcxGrid;
    dtEditPRODUTO: TIBStringField;
    dtEditPRD_CODIGO: TIntegerField;
    dtEditQTDE_ENTRADA: TIBBCDField;
    dtEditQTDE_SAIDA: TIBBCDField;
    dtEditTOTAL_ENT: TIBBCDField;
    dtEditTOTAL_SAIDA: TIBBCDField;
    dtEditAREA_1: TIBBCDField;
    dtEditAREA_2: TIBBCDField;
    dtEditEST_INICIAL: TIBBCDField;
    dtEditSAFRA_1: TIBBCDField;
    dtEditSAFRA_2: TIBBCDField;
    dtEditPERDA_CONS: TIBBCDField;
    dtEditDEPOSITO_ENT: TIBBCDField;
    dtEditDEPOSITO_SAID: TIBBCDField;
    GridLevel1: TcxGridLevel;
    GridDBBandedTableView1: TcxGridDBBandedTableView;
    GridDBBandedTableView1PRODUTO: TcxGridDBBandedColumn;
    GridDBBandedTableView1PRD_CODIGO: TcxGridDBBandedColumn;
    GridDBBandedTableView1QTDE_ENTRADA: TcxGridDBBandedColumn;
    GridDBBandedTableView1QTDE_SAIDA: TcxGridDBBandedColumn;
    GridDBBandedTableView1TOTAL_ENT: TcxGridDBBandedColumn;
    GridDBBandedTableView1TOTAL_SAIDA: TcxGridDBBandedColumn;
    GridDBBandedTableView1AREA_1: TcxGridDBBandedColumn;
    GridDBBandedTableView1AREA_2: TcxGridDBBandedColumn;
    GridDBBandedTableView1EST_INICIAL: TcxGridDBBandedColumn;
    GridDBBandedTableView1SAFRA_1: TcxGridDBBandedColumn;
    GridDBBandedTableView1SAFRA_2: TcxGridDBBandedColumn;
    GridDBBandedTableView1PERDA_CONS: TcxGridDBBandedColumn;
    GridDBBandedTableView1DEPOSITO_ENT: TcxGridDBBandedColumn;
    GridDBBandedTableView1DEPOSITO_SAID: TcxGridDBBandedColumn;
    cxStyle15: TcxStyle;
    cbProdutor: TcxDBLookupComboBox;
    cxLabel2: TcxLabel;
    dsProdutor: TDataSource;
    lstProdutores: TIBQuery;
    lstProdutoresCODIGO: TIntegerField;
    lstProdutoresNOME: TIBStringField;
    lstPropriedade: TIBQuery;
    lstPropriedadeCODIGO: TIntegerField;
    lstPropriedadeNOME: TIBStringField;
    dsPropriedade: TDataSource;
    mtbFiltroPRODUTOR: TIntegerField;
    mtbFiltroPROPRIEDADE: TIntegerField;
    mtbFiltroANO_BASE: TIntegerField;
    btnConfigura: TdxBarButton;
    ActConfigura: TAction;
    dtEditSALDO_QTDE: TIBBCDField;
    dtEditSALDO_VALOR: TIBBCDField;
    GridDBBandedTableView1SALDO_QTDE: TcxGridDBBandedColumn;
    GridDBBandedTableView1SALDO_VALOR: TcxGridDBBandedColumn;
    edtRel: TIBDataSet;
    edtRelCODIGO: TIntegerField;
    edtRelCODIGO2: TIBStringField;
    dtEditRel: TDataSource;
    ppRel: TppDBPipeline;
    ppLayoutRel: TppDBPipeline;
    Designer_Rel: TppDesigner;
    rptRel: TppReport;
    ppParameterList1: TppParameterList;
    ActImprimir: TAction;
    ActConfigRel: TAction;
    edtRelDAP: TMemoField;
    btnConfigRel: TdxBarButton;
    lstSaldoProduto: TIBQuery;
    dsSaldoProduto: TDataSource;
    lstSaldoProdutoCOD_TERCEIRO: TIntegerField;
    lstSaldoProdutoTERCEIRO: TIBStringField;
    lstSaldoProdutoPRODUTO: TIBStringField;
    lstSaldoProdutoCOD_PRODUTO: TIntegerField;
    lstSaldoProdutoSALDO: TIBBCDField;
    ppSub1: TppDBPipeline;
    dtEditPRODUTOR: TIBStringField;
    dtEditPROPRIEDADE_NOME: TIBStringField;
    dtEditINSC_ESTADUAL: TIBStringField;
    dtEditDAP_ANO_BASE: TIntegerField;
    lstParametro: TIBQuery;
    lstParametroCODIGO: TIntegerField;
    lstParametroUSUARIO: TIntegerField;
    lstParametroDATA_MOVTO: TDateField;
    lstParametroOPERACAO: TIntegerField;
    lstParametroPRODUTOR: TIntegerField;
    lstParametroTERCEIRO: TIntegerField;
    lstParametroPROPRIEDADE: TIntegerField;
    lstParametroPRODUTO: TIntegerField;
    lstParametroANO_BASE: TIntegerField;
    ppTitleBand6: TppTitleBand;
    ppShape22: TppShape;
    ppLabel1: TppLabel;
    ppLabel24: TppLabel;
    ppDBText19: TppDBText;
    ppLabel25: TppLabel;
    ppDBText20: TppDBText;
    ppDBText21: TppDBText;
    ppLabel26: TppLabel;
    ppLabel27: TppLabel;
    ppDBText22: TppDBText;
    ppHeaderBand1: TppHeaderBand;
    ppShape1: TppShape;
    ppShape2: TppShape;
    ppShape3: TppShape;
    ppLabel2: TppLabel;
    ppLabel3: TppLabel;
    ppLabel4: TppLabel;
    ppShape4: TppShape;
    ppLabel5: TppLabel;
    ppLabel6: TppLabel;
    ppLabel7: TppLabel;
    ppLine1: TppLine;
    ppLine2: TppLine;
    ppLine3: TppLine;
    ppLabel8: TppLabel;
    ppLabel9: TppLabel;
    ppLabel10: TppLabel;
    ppLine4: TppLine;
    ppLine5: TppLine;
    ppLine6: TppLine;
    ppLabel11: TppLabel;
    ppLine7: TppLine;
    ppLine8: TppLine;
    ppLabel12: TppLabel;
    ppLabel13: TppLabel;
    ppLine9: TppLine;
    ppLabel14: TppLabel;
    ppLabel15: TppLabel;
    ppLabel16: TppLabel;
    ppLabel17: TppLabel;
    ppLabel18: TppLabel;
    ppLine10: TppLine;
    ppLine11: TppLine;
    ppLine12: TppLine;
    ppLine13: TppLine;
    ppDetailBand30: TppDetailBand;
    ppShape15: TppShape;
    ppShape14: TppShape;
    ppShape13: TppShape;
    ppShape7: TppShape;
    ppShape5: TppShape;
    ppDBText1: TppDBText;
    ppShape6: TppShape;
    ppDBText2: TppDBText;
    ppDBText3: TppDBText;
    ppShape8: TppShape;
    ppDBText4: TppDBText;
    ppShape9: TppShape;
    ppDBText5: TppDBText;
    ppShape10: TppShape;
    ppDBText6: TppDBText;
    ppShape11: TppShape;
    ppDBText7: TppDBText;
    ppShape12: TppShape;
    ppDBText8: TppDBText;
    ppDBText9: TppDBText;
    ppDBText10: TppDBText;
    ppDBText11: TppDBText;
    ppShape16: TppShape;
    ppDBText12: TppDBText;
    ppShape17: TppShape;
    ppDBText13: TppDBText;
    ppShape18: TppShape;
    ppDBText14: TppDBText;
    ppFooterBand5: TppFooterBand;
    ppSummaryBand2: TppSummaryBand;
    ppSubReport1: TppSubReport;
    ppChildReport1: TppChildReport;
    ppTitleBand1: TppTitleBand;
    ppLabel19: TppLabel;
    ppDetailBand1: TppDetailBand;
    ppShape19: TppShape;
    ppDBText16: TppDBText;
    ppDBText17: TppDBText;
    ppDBText18: TppDBText;
    ppSummaryBand1: TppSummaryBand;
    ppGroup1: TppGroup;
    ppGroupHeaderBand1: TppGroupHeaderBand;
    ppShape20: TppShape;
    ppLabel21: TppLabel;
    ppDBText15: TppDBText;
    ppLabel23: TppLabel;
    ppLabel22: TppLabel;
    ppGroupFooterBand1: TppGroupFooterBand;
    ppShape21: TppShape;
    ppDBCalc1: TppDBCalc;
    ppLabel20: TppLabel;
    dxBarButton1: TdxBarButton;
    ActHelp: TAction;
    rptHelp: TppReport;
    ppTitleBand2: TppTitleBand;
    ppHeaderBand2: TppHeaderBand;
    ppDetailBand2: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppSummaryBand3: TppSummaryBand;
    ppParameterList2: TppParameterList;
    ppRichText1: TppRichText;
    procedure FormShow(Sender: TObject);
    procedure lstPropriedadeBeforeOpen(DataSet: TDataSet);
    procedure ActFilterExecute(Sender: TObject);
    procedure GridEnter(Sender: TObject);
    procedure mtbFiltroPRODUTORValidate(Sender: TField);
    procedure ActConfiguraExecute(Sender: TObject);
    procedure ActConfigRelExecute(Sender: TObject);
    procedure ActImprimirExecute(Sender: TObject);
    procedure lstParametroBeforeOpen(DataSet: TDataSet);
    procedure ActHelpExecute(Sender: TObject);
  private
    { Private declarations }
    procedure abreconsultas;
  public
    { Public declarations }
  end;

var
  frmConsultaDAP: TfrmConsultaDAP;

implementation

uses untDmPrincipal;

{$R *.dfm}

procedure TfrmConsultaDAP.FormShow(Sender: TObject);
begin
  inherited;
  lstProdutores.Close;
  lstProdutores.Open;

  abreconsultas;

  cbProdutor.SetFocus;

  lstParametro.Close;
  lstParametro.Open;


  if lstParametroANO_BASE.AsInteger > 0 then
    mtbFiltroANO_BASE.Value := lstParametroANO_BASE.AsInteger
  else
    mtbFiltroANO_BASE.Value :=  YearOf(date);

end;

procedure TfrmConsultaDAP.lstPropriedadeBeforeOpen(DataSet: TDataSet);
begin
  inherited;
  TIBQuery(DataSet).ParamByName('codigo').value := mtbFiltroPRODUTOR.AsInteger;
   TIBQuery(DataSet).ParamByName('ano').value := mtbFiltroANO_BASE.AsInteger;
end;

procedure TfrmConsultaDAP.ActFilterExecute(Sender: TObject);
begin
  inherited;
  Grid.SetFocus;
  dtEdit.Close;
  dtEdit.ParamByName('propriedade').value := mtbFiltroPROPRIEDADE.AsInteger;
  dtEdit.ParamByName('ano_base').value := mtbFiltroANO_BASE.AsInteger;
  dtEdit.Open;
end;

procedure TfrmConsultaDAP.GridEnter(Sender: TObject);
begin
  inherited;
  ActFilter.Execute;
end;

procedure TfrmConsultaDAP.abreconsultas;
begin
  lstPropriedade.Close;
  lstPropriedade.Open;
end;

procedure TfrmConsultaDAP.mtbFiltroPRODUTORValidate(Sender: TField);
begin
  inherited;
  abreconsultas;
end;

procedure TfrmConsultaDAP.ActConfiguraExecute(Sender: TObject);
begin
  inherited;
  TcxGridTableController(Grid.FocusedView.Controller).Customization := True;
end;

procedure TfrmConsultaDAP.ActConfigRelExecute(Sender: TObject);
begin
  inherited;
  edtRel.close;
  edtRel.parambyname('codigo').value := 1;
  edtRel.Open;

  rptRel.Template.DatabaseSettings.Name := edtRelCODIGO2.asstring;
  rptRel.Template.LoadFromDatabase;
  Designer_Rel.Show;
  edtRel.edit;

  edtRel.Transaction.CommitRetaining;
end;

procedure TfrmConsultaDAP.ActImprimirExecute(Sender: TObject);
begin
  inherited;
  edtRel.close;
  edtRel.parambyname('codigo').value := 1;
  edtRel.Open;

  lstSaldoProduto.close;
  lstSaldoProduto.ParamByName('ano_base').value := mtbFiltroANO_BASE.AsInteger;
  lstSaldoProduto.ParamByName('cod_propriedade').value := mtbFiltroPROPRIEDADE.asinteger;
  lstSaldoProduto.open;

  rptRel.Template.DatabaseSettings.Name := edtRelCODIGO2.asstring;
  rptRel.Template.LoadFromDatabase;

  rptRel.print;
end;

procedure TfrmConsultaDAP.lstParametroBeforeOpen(DataSet: TDataSet);
begin
  inherited;
  lstParametro.ParamByName('usuario').value := dmPrincipal.usuario_logado_codigo;
end;

procedure TfrmConsultaDAP.ActHelpExecute(Sender: TObject);
begin
  inherited;
  rptHelp.Print; 
end;

end.
